import GeoJsonSource from "../../../src/data/source/vector/GeoJsonSource";
import WebFeatureSource from "../../../src/data/source/web/WebFeatureSource";
import CsvSource from "../../../src/data/source/vector/CsvSource";
import NewHeatmapLayer from "../../../src/layer/theme/NewHeatmapLayer";
import { LayerEventType } from "../../../src/event/EventType";

/**
 * 添加heatmap图层
 * @param {} earth 
 */
export function add_theme_heatmap_layer(earth){

    //1. 创建Source
    // let source = new GeoJsonSource("geojson", {
    //     //url : "/resource/json/beijing.json"
    //     url : "/resource/json/heatmap_2.json"
    // });
    /** 创建GeoJson Source */
    //let source = _create_heatmap_geojson_source();
    //let source = _create_heatmap_wfs_source();
    let source = _create_heatmap_csv_source();


    //2. 创建Layer，将Source作为Layer属性
    let layer = new NewHeatmapLayer("heatmap", {
        source : source,
        valueFiled : undefined
    });

    /**
     * 注册Layer加载完成事件，加载完成后缩放到图层
     */
    layer.on(LayerEventType.LOADED, function(evt){
        earth.zoomTo(layer);
    })

    earth.addLayer(layer);
}



/**
 * 创建Heatmap的GeoJsonSource
 * @returns 
 */
function _create_heatmap_geojson_source(){
    let source = new GeoJsonSource("geojson", {
        //url : "/resource/json/beijing.json"
        url : "/resource/json/heatmap_2.json"
    });
    return source;
}

/**
 * 创建Heatmap的WFS DataSource
 * @returns 
 */
function _create_heatmap_wfs_source(){

    let typeName = "radi:heatmap";
    let filter = undefined;

    let source = new WebFeatureSource("xxx", {
        url : "/geoserver/ows",
        typeName : typeName,
        fields : [],
        filter : filter
    })

    return source;
}

function _create_heatmap_csv_source(){
    let url = "/resource/csv/cities.csv";
    let source = new CsvSource("csv", {
        url: url, 
        header : true,
        fields :  {
            x : "X",
            y : "Y"
        }
    });
    return source;
}
